/**
 * Copyright (c) 2010 by Kevin Bierhoff.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *    1. Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *    3. Neither the names of the authors nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.googlecode.syper.javasyp.checker;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.core.dom.IVariableBinding;

import com.googlecode.syper.javasyp.formulae.Formula;

/**
 * @author kevin
 * @since Jan 30, 2010
 *
 */
public class Contract {

	public static final String RESULT_VAR_NAME = "return";
	public static final String THIS_VAR_NAME = "this";

	private List<String> params = Collections.emptyList();
	private Formula pre;
	private Formula post;
	private Map<String, Set<IVariableBinding>> modified;

	void setPre(Formula pre) {
		this.pre = pre;
	}

	void setPost(Formula post) {
		this.post = post;
	}

	void addParam(String identifier) {
		if (params.isEmpty())
			params = new ArrayList<String>(2 /* start with 2 parameters */);
		params.add(identifier);
	}

	void setModified(Map<String, Set<IVariableBinding>> modified) {
		this.modified = modified;
	}

	public List<String> getParams() {
		return params;
	}

	public Formula getPre() {
		return pre;
	}

	public Formula getPost() {
		return post;
	}

	/**
	 * Returns map from formal parameter names to
	 * <ul>
	 * <li>possibly empty set of the parameter's modified fields
	 * if the parameter carries a modifying permission (initially Excl only);
	 * a {@code null} value in the set means the parameter is an array whose
	 * cells are annotated as modifiable.
	 * <li>{@code null} if the parameter carries no modifying permission
	 * </ul>
	 * non-{@code null} map values hence identify parameters with modifying
	 * permissions, which {@link HeapMapLogicMethodVisitor} uses to exclude
	 * those parameters from protecting their fields from modification.
	 * @return map from formal parameter names to modified fields or {@code null}
	 * if the parameter cannot modify fields through given permission
	 */
	public Map<String, Set<IVariableBinding>> getModified() {
		return modified;
	}
}
